package online.shenjian.hadoop.reducejoin;

import lombok.Data;
import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author shenjian
 * @since 2023/2/25
 */
@Data
public class OrderProductDto implements Writable {

    private String id = ""; // 订单ID
    private String pid = ""; // 商品ID
    private int amount = 0; // 商品数量
    private String productName = ""; // 商品名称
    private String flag = ""; // 记录表类型order或product

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(id);
        out.writeUTF(pid);
        out.writeInt(amount);
        out.writeUTF(productName);
        out.writeUTF(flag);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.id = in.readUTF();
        this.pid = in.readUTF();
        this.amount = in.readInt();
        this.productName = in.readUTF();
        this.flag = in.readUTF();
    }

    @Override
    public String toString() {
        return id + "\t" + productName + "\t" + amount;
    }
}
